<script setup lang="ts">
import { removeToken, setToken } from '@utils/authorization/token'
import wx from 'weixin-js-sdk'
import { WxUtil } from '@utils/wx-util'
import YkYsVideo from '@yk/components/ys-video/YkYsVideo.vue'
import { VideoDTO } from '@/api/entity/video'
import { getVideoByIdAPI } from '@/api/video'

const videoId = shallowRef('')
const route = useRoute()
const router = useRouter()

onMounted(() => {
  WxUtil.isWxEnv().then((res) => {
    if (res) {
      document.title = '视频监控'
      if (route.query.id) {
        videoId.value = route.query.id.toString()
        getVideo()
      } else {
        ElMessage.warning('参数异常')
        setTimeout(() => {
          (wx.miniProgram as NonNullable<any>).navigateBack()
        }, 2000)
      }
    } else {
      router.back()
    }
  })
})
function getVideo () {
  getVideoByIdAPI({ id: videoId.value }).then((res) => {
    res.result().then((rdata) => {
      ysVideo.value = rdata.data
    })
  })
}

const ysVideo = shallowRef<VideoDTO>()

</script>

<template>
  <div class="d-flex-center">
    <yk-ys-video v-if="ysVideo" :ys-video="ysVideo" style="height: 100vmin;" />
  </div>
</template>

<style scoped lang="scss">

</style>
